#include<bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 1e5 + 5;

int n,m,l,maxv;

struct node{
    int d,v,a;
}t[N];

int pos[N];
double tim[N];
bool vis[30][30];
bool li[30];


void solve()
{
    memset(li,0,sizeof(li));
    memset(vis,0,sizeof(vis));
    cin >> n >> m >> l >> maxv;
    bool flagA = 1;
    for(int i = 1;i <= n;i++)
    {
        cin >> t[i].d >> t[i].v >> t[i].a;
        if(t[i].a != 0)
            flagA = 0;
    }
    int maxn = 0;
    for(int i = 1;i <= m;i++)
        cin >> pos[i],maxn = max(maxn,pos[i]);
    if(flagA == 1)
    {
        int cnt = 0;
        int q2 = 0;
        for(int i = 1;i <= n;i++)
        {
            if(t[i].v > maxv && t[i].d <= maxn)
            {
                cnt++;
                q2 = 1;
            }
        }
        cout << cnt << " " << m-q2 << endl;
        return;
    }
    if(n <= 20)
    {
        int cnt = 0,q2 = 0;
        for(int i = 1;i <= n;i++)
        {
            if(t[i].d > maxn){
                li[i] = 1;
                continue;
            }
            if(t[i].v == maxv && t[i].a <= 0){
                li[i] = 1;
                continue;
            } 
            if(t[i].v > maxv && t[i].d <= maxn && t[i].a >= 0)
            {
                cnt++;
                for(int k = 1;k <= m;k++)
                {
                    if(pos[k] > t[i].d)
                        vis[i][k] = true;
                }
                continue;
            }
            if(t[i].a > 0)
            {
                if(maxv < t[i].v)
                {
                    tim[i] = 0;
                    cnt++;
                    for(int k = 1;k <= m;k++)
                    {
                        if(pos[k] > t[i].d)
                            vis[i][k] = true;
                    }
                }
                else 
                {
                    tim[i] = (maxv - t[i].v) * 1.0 / t[i].a;
                    double pq = (t[i].v + maxv) * tim[i] * 1.0 / 2;
                    double l = t[i].d,r = t[i].d + pq;
                    bool flag = 0;
                    for(int k = 1;k <= m;k++)
                    {
                        
                        if(pos[k] > r)
                        {
                            flag = 1;vis[i][k] = true;
                        }
                    }
                    if(flag == 1)
                        cnt++;

                }
            }
            else    
            {
                if(t[i].v > maxv) 
                {
                    tim[i] = (t[i].v - maxv) * 1.0 / (-t[i].a);
                    double pq = (t[i].v + maxv) * tim[i] * 1.0 / 2;
                    double l = t[i].d,r = t[i].d + pq;
                    bool flag = 0;
                    for(int k = 1;k <= m;k++)
                    {
                        
                        if(l <= pos[k] && pos[k] < r)
                        {
                            flag = 1;vis[i][k] = true;
                        }
                    }
                    if(flag == 1)
                        cnt++;
                }
            }
        }
        q2 = m;
        int num[20];
        for(int k = 18;k <= (1<<(m+1)-1);k++)
        {
            int x = k,c = 0,cm = 0;
            int pp = 1;
            while(x)
            {
                if(x&1) num[pp] = 1,cm++;
                else num[pp] = 0;
                pp++;
                x=x>>1;
            }
            for(int i = 1;i <= n;i++)
            {
                if(li[i]==1)continue;
                for(int z = 1;z <= m;z++)
                    if(num[z]==1){
                        if(vis[i][z]==1)
                        {
                            c++;break;
                        }
                    }
            }
            if(c==cnt)
            {
                q2 = min(q2,cm);
            }
        }
        cout << cnt << " " << m-q2 << endl;
        return;
    }
    int cnt = 0;
    int p = 0,cntp = 0;
    int q2 = 0;
    for(int i = 1;i <= n;i++)
    {
        if(t[i].d > maxn)continue;
        if(t[i].v >= maxv && t[i].d <= maxn && t[i].a >= 0)
            cnt ++;
        if(t[i].v == maxv && t[i].a <= 0) continue;
        if(t[i].a > 0)
        {
            if(maxv < t[i].v)
            {
                tim[i] = 0;
                cnt++;
                // p = max()
                q2 = 1;
            }
            else 
            {
                tim[i] = (maxv - t[i].v) * 1.0 / abs(t[i].a);
                double pq = (t[i].v + maxv) * tim[i] * 1.0 / 2;
                if(pq + t[i].d <= maxn)
                {
                    cnt++;
                    q2 = 1;
                }
            }
        }
    }
    cout << cnt << " " << m-q2 << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int Test_case=1;
    cin >> Test_case;
    while(Test_case--)solve();
    return 0;
}